
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    userBean: { fullName: '长沙市系统管理员', isCenter: 0, isUpdatePwd: 0, orders: 0, orgId: '3', orgName: '长沙市', userId: '20190111090132056-1083541888272695307' },
    codeMap: {
      auditStatu: {
        0: { field: 'auditStatus', key: '0', value: '待审核', memo: '', sn: 1, id: '2019041800001', pid: '' },
        1: { field: 'auditStatus', key: '1', value: '已通过', memo: '', sn: 1, id: '2019041800002', pid: '' },
        2: { field: 'auditStatus', key: '3', value: '全部', memo: '', sn: 1, id: '2019041800003', pid: '' }
      }
    },
    menuList: [
      {
        path: '/guide',
        menuId: '201908221505',
        children: [
          { path: 'index', menuId: '2019082215050' },
          { path: 'system', menuId: '2019082215080' },
          { path: 'component', menuId: '2019082215089' }
        ]
      }
    ],
    // 指令的id能和用户的btnList列表项的id匹配上刚显示按钮 否则移除
    btnList: [
      { id: '201908211522', name: '编辑' },
      { id: '201908211523', name: '新增' },
      { id: '201908211524', name: '自定义表格1删除权限' },
      { id: '201908211525', name: '审核' }
    ]
  },
  'editor-token': {
    roles: ['edit'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    userBean: { fullName: '长沙市编辑员', isCenter: 0, isUpdatePwd: 0, orders: 0, orgId: '3', orgName: '长沙市', userId: '20190111090132056-1083541888272695307' },
    codeMap: {
      auditStatu: {
        0: { field: 'auditStatus', key: '0', value: '待审核', memo: '', sn: 1, id: '2019041800001', pid: '' },
        1: { field: 'auditStatus', key: '1', value: '已通过', memo: '', sn: 1, id: '2019041800002', pid: '' },
        2: { field: 'auditStatus', key: '3', value: '全部', memo: '', sn: 1, id: '2019041800003', pid: '' }
      }
    },
    menuList: [
      {
        path: '/guide',
        menuId: '201908221505',
        children: [
          { path: 'system', menuId: '2019082215080' }
        ]
      }
    ],
    btnList: [
      { id: '201908211522', name: '编辑' },
      { id: '201908211523', name: '新增' },
      { id: '201908211525', name: '审核' }
    ]
  }
}

export default [
  // user login
  {
    url: '/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.'
        }
      }

      return {
        code: 0,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 0,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 0,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 0,
        data: 'success'
      }
    }
  }
]
